/**
 * @filename:PurchaseOrder
 * @project com/lwl/blue  V1.0
 * @author: group3_pzj
 */
package com.lwl.blue.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableField;
import com.lwl.blue.commont.base.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Arrays;

/**
 * <p>采购订单主表实体</p>
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("purchase_order_3")
public class PurchaseOrder extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "purchase_order_id", type = IdType.INPUT)
    @ApiModelProperty(name = "id", value = "主键ID")
    private String id;
    @ApiModelProperty(name = "purchaseOrderId", value = "前端展示使用的主键ID")
    @TableField(exist = false)
    private String purchaseOrderId;

    @ApiModelProperty(name = "orderNo", value = "订单号")
    private String orderNo;
    @ApiModelProperty(name = "cancelInnerId", value = "采购订单号核销内码")
    private String cancelInnerId;
    @ApiModelProperty(name = "cancelNo", value = "采购订单核销号")
    private String cancelNo;
    @ApiModelProperty(name = "lastBizDocNo", value = "末级业务单据号")
    private String lastBizDocNo;

    @ApiModelProperty(name = "signDate", value = "签约日期")
    @JSONField(format = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private String signDate;
    @ApiModelProperty(name = "validStartDate", value = "订单有效起始日期")
    @JSONField(format = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private String validStartDate;
    @ApiModelProperty(name = "validEndDate", value = "订单有效结束日期")
    @JSONField(format = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private String validEndDate;

    @ApiModelProperty(name = "signLocation", value = "签约地点")
    private String signLocation;
    @ApiModelProperty(name = "deliveryPlanType", value = "交期计划方式")
    private String deliveryPlanType;
    @ApiModelProperty(name = "deliveryTerms", value = "交期条款")
    private String deliveryTerms;

    @ApiModelProperty(name = "expectedDeliveryDate", value = "预计交货日期")
    @JSONField(format = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private String expectedDeliveryDate;
    @ApiModelProperty(name = "pickupPeriodStart", value = "提货期限开始")
    @JSONField(format = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private String pickupPeriodStart;
    @ApiModelProperty(name = "pickupPeriodEnd", value = "提货期限结束")
    @JSONField(format = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private String pickupPeriodEnd;

    @ApiModelProperty(name = "paymentTerms", value = "付款期限")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private String paymentTerms;

    @ApiModelProperty(name = "creatorId", value = "创建人ID")
    private String creatorId;
    @ApiModelProperty(name = "updaterId", value = "修改人ID")
    private String updaterId;

    @ApiModelProperty(name = "docVersion", value = "单据版本号")
    private String docVersion;
    @ApiModelProperty(name = "versionEffectiveTime", value = "本版本生效时间")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private String versionEffectiveTime;
    @ApiModelProperty(name = "originalEffectiveDate", value = "原始版本生效日期")
    @JSONField(format = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private String originalEffectiveDate;

    @ApiModelProperty(name = "docStatus", value = "单据状态")
    private Integer docStatus;
    @ApiModelProperty(name = "redFlag", value = "红冲标记")
    private String redFlag;

    @ApiModelProperty(name = "externalCancelInnerId", value = "外部采购订单核销内码")
    private String externalCancelInnerId;
    @ApiModelProperty(name = "externalCancelNo", value = "外部采购订单核销外码")
    private String externalCancelNo;
    @ApiModelProperty(name = "externalSystemType", value = "外部系统类型")
    private String externalSystemType;
    @ApiModelProperty(name = "externalDocInnerId", value = "外部系统单据内码")
    private String externalDocInnerId;
    @ApiModelProperty(name = "externalDocNo", value = "外部系统单号")
    private String externalDocNo;

    @ApiModelProperty(name = "bizSource", value = "业务来源")
    private String bizSource;
    @ApiModelProperty(name = "bizSourceDesc", value = "业务来源说明")
    private String bizSourceDesc;
    @ApiModelProperty(name = "sourceDocNo", value = "来源单据号")
    private String sourceDocNo;
    @ApiModelProperty(name = "bizDocCode", value = "业务单据编码")
    private String bizDocCode;

    @ApiModelProperty(name = "supId", value = "供应商ID（supplier.id）")
    private Integer supId;
    @ApiModelProperty(name = "supName", value = "供应商名称")
    @TableField(exist = false)
    private String supName;

    // 预留属性字段
    @ApiModelProperty(name = "attr_1", value = "预留属性1")
    @TableField("attr_1")
    private String attr1;
    @ApiModelProperty(name = "attr_2", value = "预留属性2")
    @TableField("attr_2")
    private String attr2;
    @ApiModelProperty(name = "attr_3", value = "预留属性3")
    @TableField("attr_3")
    private String attr3;
    @ApiModelProperty(name = "attr_4", value = "预留属性4")
    @TableField("attr_4")
    private String attr4;
    @ApiModelProperty(name = "attr_5", value = "预留属性5")
    @TableField("attr_5")
    private String attr5;
    @ApiModelProperty(name = "attr_6", value = "预留属性6")
    @TableField("attr_6")
    private String attr6;
    @ApiModelProperty(name = "attr_7", value = "预留属性7")
    @TableField("attr_7")
    private String attr7;
    @ApiModelProperty(name = "attr_8", value = "预留属性8")
    @TableField("attr_8")
    private String attr8;
    @ApiModelProperty(name = "attr_9", value = "预留属性9")
    @TableField("attr_9")
    private String attr9;
    @ApiModelProperty(name = "attr_10", value = "预留属性10")
    @TableField("attr_10")
    private String attr10;

    @ApiModelProperty(name = "totalAmount", value = "订单总金额")
    private BigDecimal totalAmount;
    @ApiModelProperty(name = "totalTaxFreeAmount", value = "不含税总金额")
    private BigDecimal totalTaxFreeAmount;
    @ApiModelProperty(name = "taxRate", value = "增值税税率")
    private BigDecimal taxRate;
    @ApiModelProperty(name = "taxAmount", value = "增值税金额")
    private BigDecimal taxAmount;
    @ApiModelProperty(name = "isTempPrice", value = "是否暂定价")
    private String isTempPrice;

    // 添加getter方法进行验证和规范化
    public String getDeliveryPlanType() {
        if (this.deliveryPlanType == null || this.deliveryPlanType.trim().isEmpty()) {
            return "FIXED_DATE"; // 默认值
        }

        String normalized = this.deliveryPlanType.trim().toUpperCase();
        if (Arrays.asList("FIXED_DATE", "BY_ORDER_RATIO", "INSTALLMENT").contains(normalized)) {
            return normalized;
        } else {
            return "FIXED_DATE"; // 无效值转为默认值
        }
    }

    // 添加setter方法进行验证
    public void setDeliveryPlanType(String deliveryPlanType) {
        if (deliveryPlanType == null || deliveryPlanType.trim().isEmpty()) {
            this.deliveryPlanType = "FIXED_DATE";
            return;
        }

        String normalized = deliveryPlanType.trim().toUpperCase();
        if (Arrays.asList("FIXED_DATE", "BY_ORDER_RATIO", "INSTALLMENT").contains(normalized)) {
            this.deliveryPlanType = normalized;
        } else {
            this.deliveryPlanType = "FIXED_DATE"; // 无效值转为默认值
        }
    }

    // 添加setter方法进行验证并设置默认值
    public void setBizSource(String bizSource) {
        if (bizSource == null || bizSource.trim().isEmpty()) {
            this.bizSource = "INTERNAL"; // 设置为默认值"内部"
            return;
        }

        String normalized = bizSource.trim().toUpperCase();
        if (Arrays.asList("INTERNAL", "EXTERNAL", "FRAMEWORK", "OTHER").contains(normalized)) {
            this.bizSource = normalized;
        } else {
            this.bizSource = "INTERNAL"; // 无效值转为默认值"内部"
        }
    }

    // 添加getter方法确保一致性
    public String getBizSource() {
        if (this.bizSource == null || this.bizSource.trim().isEmpty()) {
            return "INTERNAL"; // 确保返回默认值
        }
        return this.bizSource;
    }
}